<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<meta content="email=no" name="format-detection" />
		<title>终端报装</title>
		<link rel="stylesheet" href="../../css/s_plus.css" />
		<link rel="stylesheet" href="../../css/base.css" />
		<link rel="stylesheet" href="../../css/layout.css" />
		<link rel="stylesheet" href="../../css/choice.css" />
		<link rel="stylesheet" href="../../css/hui.css" />


		<script type="text/javascript" src="../../libs/vue.js"></script>
		<script type="text/javascript" src="../../js/jquery.1.9.1.min.js"></script>
		<script type="text/javascript" src="../../js/app/url.js"></script>
		<script type="text/javascript" src="../../js/mui.min.js"></script>

		<script type="text/javascript" src="../../libs/hui.js"></script>
		<script type="text/javascript" src="../../js/app/api.js?time=20181210"></script>
		<script type="text/javascript" src="../../js/control/pop.js"></script>
		<script type="text/javascript" src="../../js/md5.js"></script>
		<script type="text/javascript" src="../../js/control/select/iosSelect.js"></script>
		<link rel="stylesheet" href="../../js/control/select/iosSelect.css" />
		<script type="text/javascript" src="../../js/control/swal/sweetalert.min.js"></script>
		<link rel="stylesheet" href="../../js/control/swal/sweetalert.css" />
		<script src="../../js/control/lrz.bundle.js"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=a82yNQICnHARgGpKuPH1wWZWQcBD2Llo"></script>
		<script type="text/javascript" src="../../js/app/ble.js"></script>

	</head>

	<body>
		<div id="wrapper">
			<header class="f_l maxbox subhead">
				<a class="back" @click="back"><i class="iconfont">&#xe605;</i></a>
				<h1>终端报装</h1>
			</header>
			<section class="f_l maxbox edit_list">
				<ul>
					<li>
						<a class="edit_a">
							<b>终端信息</b>
							<p>
							</p>
						</a>
					</li>
				</ul>
			</section>

			<section class="f_l maxbox edit_list">
				<ul>
					<li>
						<a class="edit_a">
							<b>终端ID</b>
							<p><input v-model="params.termimalCode" class="edit_txt" name="" readonly="" type="text">
								<!--<select v-model="params.termimalCode">
									<option v-for="item in zdlist" :value="item.TERMIMAL_CODE">{{item.TERMIMAL_CODE}}</option>
								</select>-->
							</p>
						</a>
					</li>
					<li>
						<b>责任单位</b>
						<p><input v-model="params.respUnit" class="edit_txt" name="" type="text"></p>
					</li>
					<li>
						<b>所属路段</b>
						<p><input v-model="params.belongStreet" class="edit_txt" name="" type="text"></p>
					</li>
					
						<li>
						<b>管井类型</b>
						<p><input v-model="params.gjType" class="edit_txt" name="" type="text"></p>
					</li>
					
					
						<li>
						<b>经纬度</b>
						<p>	{{params.longitude}},
							{{params.latitude}}   </p>
					</li>
						<li>
						<b></b>
						<p>	 <a @click="mapLatLng">地图选点</a><input  class="edit_txt" name="" type="text"></p>
					</li>
					<li>
						<b>安装时间</b>
						<p><input readonly="readonly" id="installTime" v-model="params.installTime" class="edit_txt" name="" type="text"></p>
					</li>
					<!--<li>
						<b>告警状态</b>
						<p>
							<select v-model="params.status">
								<option value="0">无告警</option>
								<option value="1">一般告警</option>
								<option value="2">严重告警</option>
								<option value="3">工单处理中</option>
							</select>
						</p>
					</li>-->

				</ul>
			</section>

			<section class="f_l maxbox block_two">
				<dl>
					<dt>
      <h2>上传图片</h2>
    </dt>
					<dd class="photo_list">
						<ul>
							<li v-for="item in imgs"><img :src="item" alt="" /></li>
							<!--<li><img src="images/map.jpg" alt="" /></li>
							<!--<li><a><i class="iconfont">&#xe626;</i></a> </li>-->
							<!--<li><input class="fileControl" id="picture" type="file" accept="image/*" multiple="multiple"></li>-->
							<li><a id="selectImgBtn"><i class="iconfont">&#xe626;</i></a></li>
							
						</ul>
					</dd>
				</dl>
			</section>
			
				<section class="f_l maxbox edit_list">
				<ul>
					<li>
						<a class="edit_a">
							<b>井盖信息</b>
							<p>
							</p>
						</a>
					</li>
				</ul>
			</section>
				<section class="f_l maxbox edit_list">
					
				<ul>
				
					<li>
						<b>井盖ID</b>
						<p><input v-model="jg.jgCode" class="edit_txt" name="" type="text"></p>
					</li>
					<li>
						<b>责任单位</b>
						<p><input v-model="jg.respUnit" class="edit_txt" name="" type="text"></p>
					</li>
					<li>
						<b>所属路段</b>
						<p><input  v-model="jg.belongStreet" class="edit_txt" name="" type="text"></p>
					</li>
					
						<li>
						<b>所属项目</b>
						<p>
							<select  v-model="jg.projId" @change="changeProject">
								<option v-for="item in projects" :value="item.ID" >{{item.NAME}}</option>
								<!--	<option value="ccf6eb06b1fb4b259e53636cd57a7f08">天心区</option><option value="0cf7295e308e4195a394b64130404fec">宁乡县</option><option value="ff0aff68a1cd4f598a03dc6bd374812e">岳麓区</option><option value="5f4d95cdcdf74090b6c9a85386f1edc2">开福区</option>-->
								</select>
						</p>
					</li>
					
						<li>
						<b>所属区域</b>
						<p>
							
								<select  v-model="jg.regionId">
																	<option v-for="item in areas" :value="item.id" >{{item.value}}</option>

								<!--	<option value="ccf6eb06b1fb4b259e53636cd57a7f08">天心区</option><option value="0cf7295e308e4195a394b64130404fec">宁乡县</option><option value="ff0aff68a1cd4f598a03dc6bd374812e">岳麓区</option><option value="5f4d95cdcdf74090b6c9a85386f1edc2">开福区</option><option value="7d842a96ad8f468792eff00988639751">望城区</option><option value="51b8b84ba2f84a95a7651e80206e2ed1">芙蓉区</option><option value="830eaa62023c4110ac7af62800059027">长沙县</option><option value="af7c16f4efb74f3d997aa0a76284516a">雨花区</option>-->
								</select>
							<!--<input readonly="readonly" id="installTime" v-model="jg.regionId" class="edit_txt" name="" type="text">-->
						
						</p>
					</li>
					<li>
					<b>所属材质</b>
						<p>
							
							<select v-model="jg.material" id="material" name="material">
										<option value="1">复合材料</option>
										<option value="2">铸铁</option>
										<option value="3">水泥</option>
										<option value="4">其他</option>
									</select>
							
							<!--<input readonly="readonly" id="installTime" v-model="jg.material" class="edit_txt" name="" type="text">-->
						</p>
					</li>
					
						<li>
					<b>型号规格</b>
						<p>
							
							<select id="model" v-model="jg.model" >
										<option value="1">圆形</option>
										<option value="2">方形</option>
										<option value="3">外方内圆</option>
										<option value="4">其他</option>
									</select>
							<!--<input  v-model="jg.model" class="edit_txt" name="" type="text"></p>-->
					</li>
						<li>
					<b>长度(mm)</b>
						<p><input  v-model="jg.modelSize1" class="edit_txt" name="" type="number"></p>
					</li>
					<li>
						<b>宽度(mm)</b>
						<p><input  v-model="jg.modelSize2" class="edit_txt" name="" type="number" ></p>
					</li>
					<li>
						<b>井边厚(mm)</b>
						<p><input  v-model="jg.modelSize3" class="edit_txt" name="" type="number"></p>
					</li>
						<li>
						<b>建设时间</b>
						<p><input readonly="readonly" id="constructionTime" v-model="jg.constructionTime" class="edit_txt" name="" type="text"></p>
					</li>
					
						<li>
						<b>使用年限</b>
						<p><input  v-model="jg.useFixedYear" class="edit_txt" name="" type="number"></p>
					</li>
							<li>
						<b>所属维护网络</b>
						<p><input  v-model="jg.blongNetwork" class="edit_txt" name="" type="text"></p>
					</li>
					<li>
						<b>承载等级</b>
						<p>
							<select v-model="jg.bearLevel">
										<option value="A">A级</option>
										<option value="B">B级</option>
										<option value="C">C级</option>
										<option value="D">D级</option>
										<option value="E">E级</option>
									</select>
							<!--<input   class="edit_txt" name="" type="text">-->
						</p>
					</li>
					
			

				</ul>
			</section>
			<section class="f_l maxbox mar_t mar_f t_c">
				<a class="btn mian_btn" @click="submitData">提交</a>
<p>&nbsp;</p>
			</section>
		</div>

		<script>
			
			
				var bleConnect;
  	
	  	
	  mui.plusReady(function() {
	  		 	
	  	 bleConnect = plus.blecontroler;
	  	var returnStr = bleConnect.init()
	  });
			
			
			window.addEventListener('refresh', function(e){//执行刷新
//location.reload();

console.log('子页面回调！！');

console.log(localStorage.getItem("p_lng"));
						console.log(localStorage.getItem("p_lat"));
						
						var lng = localStorage.getItem("p_lng");
						var lat = localStorage.getItem("p_lat");
						sp.params.longitude=lng;
						sp.params.latitude=lat;
						console.log(JSON.stringify(sp.params));
});
			
			var sp = new Vue({
				el: "#wrapper",
				data: {
					projects:[],
					areas:[],
					jg:{
						projId:"",
//						jgId:"",
						jgCode:"",
						respUnit:"",
						belongStreet:"",
						material:"1",
						model:"1",
						modelSize1:"",
						modelSize2:"",
						modelSize3:"",
						constructionTime:"",
						useFixedYear:"",
						blongNetwork:"",
						bearLevel:"A",
						regionId:"af7c16f4efb74f3d997aa0a76284516a"
					},
					selectDevice: [],
					zdlist: [],
					imgs: [],
					params: {
						gjType:"",
						termimalCode: "", //终端ID
						"jgId.cusId":"",
						//"jgId.jgId": "19",
						//						jgId:{jgId:"18"},//对应井盖ID
						jgCode: "", //CCID
						respUnit: "", //责任单位
						belongStreet: "", //所属路段
						longitude: "",
						latitude: "",
						status: "0", //告警状态
						phase: "1", //工程状态
						installTime: "", //安装时间
						imgUrl: "" //现场照片

					}

				},
			
				mounted: function() {
					console.log('返回了这里了222222')
					var zdId=localStorage.getItem("Tid");
					this.params.termimalCode=zdId;
				    
					this.jg.constructionTime=apiManage.getNowYYMMDD();
					this.params.installTime=apiManage.getNowYYMMDD();
					console.log("apiManage.getCompanyId()---"+apiManage.getCompanyId());
					this.params["jgId.cusId"] = apiManage.getCompanyId();

					$("#model option:first").prop("selected", 'selected');
					
					loadProject();
					
					
					
				},
				
				
				
				methods: {
						//唤醒终端
			wakeUp:function () {
				var zdId=localStorage.getItem("Tid");
				if(!zdId || zdId.length == 0) {
					hui.toast("请先获取终端编号");
					return;
				}
				
				

				var command = "5A1109" + zdId + "01";
				console.log("唤醒命令" + command);
				bleConnect.writeData(command, function(ret) {
					console.log("唤醒成功-返回数据:" + ret);
//					sp.notifyList = sp.notifyList.concat("唤醒成功: " + ret);
//					console.log("唤醒成功");
				}, function(err) {
					hui.closeLoading();
					alert(err);
				});
			}
			,
					changeProject:function(){
						
					
						
//						var obj = event.target;
						console.log("select projId ----"+this.jg.projId);
						
						var projectId= this.jg.projId;
							if(this.projects!=null&&this.projects.length>0){
			            	   for(var i =0;i<this.projects.length;i++){
			            			var cell = this.projects[i];
			            			if(projectId==cell.ID){
			            			   var readyIds=	cell.REGION_ID;
			            			   var readyNames=	cell.REGION_NAME;
			            			  var ids =readyIds.split(",");
			            			  var names= readyNames.split(",");
			            			  
			            			  sp.jg.regionId = ids[0];
			            			  
			            			  this.areas.length=0;
			            			  for(var y=0;y<names.length;y++){
			            			  	var k = ids[y];
			            			  	var v = names[y];
//			            			  	 this.areas.push({id:k,value:v});
										var one = {id:k,value:v};
										this.areas.push(one);
			            			  }
			            			  console.log('this.areas---'+JSON.stringify(this.areas));

			            				break;
			            			}
			            			
			            	}
			            }
					},
					mapLatLng:function(){
						localStorage.setItem("p_lng","");
						localStorage.setItem("p_lat","");
						hui.open("mapLatLng.html?time="+apiManage.getNow(), {}, true, {});  
					
					},
					selectDate: function() {
						checkDate();
					},
					

					geshi: function(param) {
						return formatTime(param);
					},
					showState: function(param) {
						//					10-新建，20-已确认，30-已完成
						if(param == '10') {
							return "新建";
						} else if(param == '20') {
							return "已确认";
						} else {
							return "已完成";

						}
					},

					back: function() {
											hui.back();
//						hui.open("terminal.html", {}, true, {});

					},

					showAlert: function(title) {
//						swal("", title, "warning");
						hui.toast(title);

					},
					submitData: function() {
					

							if(this.params.termimalCode == null || this.params.termimalCode == '') {
								this.showAlert("请输入终端ID");
								return;
							} else if(this.params.respUnit == null || this.params.respUnit == '') {
								this.showAlert("请填写责任单位");
								return;
							} else if(this.params.belongStreet == null || this.params.belongStreet == '') {
								this.showAlert('请填写所属路段');
								return;
								
							} 
							 else if(this.params.gjType == null || this.params.gjType == '') {
								this.showAlert('请填写管井类型');
								return;
								
							} 
							
							else if(this.params.installTime == null || this.params.installTime == '') {
								this.showAlert("请填写安装时间");
								return;
							} else if(this.params.phase == null || this.params.phase == '') {
								this.showAlert('请填写工程状态');
								return;
							} else if(this.params.imgUrl == null || this.params.imgUrl == '') {
								this.showAlert("请上传照片");
								return;
							} 
							
							//井盖信息相关判断
							
							else if(this.jg.jgCode == null || this.jg.jgCode== '') {
								this.showAlert("井盖ID不能为空");
								return;
							}
							else if(this.jg.respUnit == null || this.jg.respUnit== '') {
								this.showAlert("责任单位不能为空");
								return;
							}
							else if(this.jg.belongStreet == null || this.jg.belongStreet== '') {
								this.showAlert("所属路段不能为空");
								return;
							}
							
							
							else if(this.jg.regionId == null || this.jg.regionId== '') {
								this.showAlert("所属区域不能为空");
								return;
							}
							else if(this.jg.material == null || this.jg.material== '') {
								this.showAlert("所属材质不能为空");
								return;
							}
						
							else if(this.jg.model == null || this.jg.model== '') {
								this.showAlert("型号规格不能为空");
								return;
							}
								else if(this.jg.modelSize1 == null || this.jg.modelSize1== '') {
								this.showAlert("长度不能为空");
								return;
							}
								else if(this.jg.modelSize2 == null || this.jg.modelSize2== '') {
								this.showAlert("宽度不能为空");
								return;
							}
								else if(this.jg.modelSize3 == null || this.jg.modelSize3== '') {
								this.showAlert("井边厚不能为空");
								return;
							}
								
							else if(this.jg.constructionTime == null || this.jg.constructionTime== '') {
								this.showAlert("建设时间不能为空");
								return;
							}
							else if(this.jg.useFixedYear == null || this.jg.useFixedYear== '') {
								this.showAlert("使用年限不能为空");
								return;
							}
								else if(this.jg.blongNetwork == null || this.jg.blongNetwork== '') {
								this.showAlert("所属维护网络不能为空");
								return;
							}
							else if(this.jg.bearLevel == null || this.jg.bearLevel== '') {
								this.showAlert("承载等级不能为空");
								return;
							}
		
							
							else {

							}

							this.save();
						}

						,
					save: function() {

						var path = urlManager.resTerminalBuild();
						console.log("path======"+path);
						var username = localStorage.getItem("username");
						var sec = localStorage.getItem("sec_pwd");
						var time = apiManage.getNow();
						var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
						var paramKey = hex_md5(key);
						console.log("header======"+key);

	console.log("sign---"+paramKey);
//						console.log("path============================" + path);
//					
//						console.log(" jg params===================" + JSON.stringify(sp.jg));
						console.log("  params===================" + JSON.stringify(sp.params));




         var obj = sp.jg;
			for(var key in obj){
				var plusKey = "jgId."+key;
					sp.params[plusKey]=obj[key];
		
						
			}
			
			sp.params["jgCode"]=sp.jg.jgCode;
                      	console.log("params===================" + JSON.stringify(sp.params));   
//						return;


							hui.loading("信息提交中...");
						$.ajax({
							type: "POST",
							url: path,
							data: sp.params,
							            timeout: 8000,          // 设置超时时间

							beforeSend: function(request) {
								request.setRequestHeader("loginName", username);
								request.setRequestHeader("time", time);
								request.setRequestHeader("sign", paramKey);

							},
							 error: function(XMLHttpRequest, textStatus, errorThrown) {
//                      alert(XMLHttpRequest.status);
//                      alert(XMLHttpRequest.readyState);
//                      alert(textStatus);
                        
                        console.log("XMLHttpRequest.status    "+XMLHttpRequest.status);         
                        console.log("XMLHttpRequest.readyState   "+XMLHttpRequest.readyState);
                        console.log("textStatus--"+textStatus);
                        hui.closeLoading();
                        hui.toast("网络超时");

                    },
							success: function(result) {
								hui.closeLoading();
								console.log("报装返回============================" + JSON.stringify(result));
								
								if(result.error_code==null||result.error_code=='-1'){
									//var text = result.error_msg?result.error_msg:"";
									swal({  
										title: "终端报装失败",
										  text: result.error_msg,
										  type: "error",
										  showCancelButton: false,
										  confirmButtonColor: "#DD6B55",
										  confirmButtonText: "确认",
										  cancelButtonText: "取消",
										  closeOnConfirm: true,
										  closeOnCancel: false
									},
									function(isConfirm) {  
										if(isConfirm) {
//											hui.open("terminal_list.html?time="+apiManage.getNow(), {}, true, {});  
										} else { 
											 }
									});
								}
								else{
									sp.wakeUp();
									swal({  
										title: "终端报装成功",
										  text: "",
										  type: "success",
										  showCancelButton: false,
										  confirmButtonColor: "#DD6B55",
										  confirmButtonText: "确认",
										  cancelButtonText: "取消",
										  closeOnConfirm: true,
										  closeOnCancel: false
									},
									function(isConfirm) {  
										if(isConfirm) {
											hui.open("terminal_list.html?time="+apiManage.getNow(), {}, true, {});  
										} else {  }
									});
								}
								

							}
						});

					}
				}
			});

//获取项目和区域
	function loadProject() {
				var path = urlManager.getProjects();
				console.log(path);
				var username = localStorage.getItem("username");
				var sec = localStorage.getItem("sec_pwd");
				var time = apiManage.getNow();
				var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
				console.log("header---"+key);
				var paramKey =	 hex_md5(key);

			
				$.ajax({
					type: "GET",
					url: path,
					beforeSend: function(request) {
						request.setRequestHeader("loginName", username);
						request.setRequestHeader("time", time);
						request.setRequestHeader("sign", paramKey);
						//		            request.setRequestHeader("Content-Type","application/text");

					},
					success: function(result) {
						console.log("获取项目和区域============================" + JSON.stringify(result));
						
						sp.projects=result.data;
   
	   					var cell  = sp.projects[0];
	   					
	   					sp.jg.projId=cell.ID;

   					sp.changeProject();

					}
				});

			}



//			loadZDList();
			//获取终端CODE列表
			function loadZDList() {
				var path = urlManager.terminalList();
				console.log(path);
				var username = localStorage.getItem("username");
				var sec = localStorage.getItem("sec_pwd");
				var time = apiManage.getNow();
				var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
				console.log(key);
				var paramKey = hex_md5(key);

				var readyParam = {
					cusId: apiManage.getCompanyId(),
					status: "0"
				};
				$.ajax({
					type: "POST",
					data: readyParam,
					url: path,
					beforeSend: function(request) {
						request.setRequestHeader("loginName", username);
						request.setRequestHeader("time", time);
						request.setRequestHeader("sign", paramKey);
						//		            request.setRequestHeader("Content-Type","application/text");

					},
					success: function(result) {
						console.log("终端列表下拉框============================" + JSON.stringify(result));
//						sp.zdlist = result.list;

					}
				});

			}

			$(function() {
				
				
				

				var geolocation = new BMap.Geolocation();
				geolocation.getCurrentPosition(function(r) {
					//				console.log(r.point)
					if(this.getStatus() == BMAP_STATUS_SUCCESS) {

						var point = new BMap.Point(r.point.lng, r.point.lat); //用所定位的经纬度查找所在地省市街道等信息
						console.log(r.point.lng + "---" + r.point.lat); //地址信息
						sp.params.latitude = r.point.lat;
						sp.params.longitude = r.point.lng;

					} else {
						alert('定位失败，请检查您的手机定位功能是否打开' + this.getStatus());
					}
				}, {
					enableHighAccuracy: true
				})

					var imgs_index=0;
				function settingImgs(imgList) {

				
					var newUrl = imgList[0];
					if(sp.imgs == null || sp.imgs.length < 3) {
						sp.imgs.push(newUrl);
						console.log(newUrl);
						
							
					} else {
						
						sp.imgs.splice(imgs_index, 1, newUrl);
					

					}
					
						if(imgs_index==2){
							imgs_index=0;
						}
						else{
							imgs_index+=1;

						}
						console.log("imgs_index---"+imgs_index);

					sp.params.imgUrl = sp.imgs.join(",");

					console.log("sp.params.imgUrl----" + sp.params.imgUrl);
					console.log("sp.imgs--" + JSON.stringify(sp.imgs));

				}
				
				
				
				 document.getElementById('selectImgBtn').addEventListener('tap', function() { 
            if (mui.os.plus) { 
                var a = [{ 
                    title: "拍照" 
                }, { 
                    title: "从手机相册选择" 
                }]; 
                plus.nativeUI.actionSheet({ 
                    title: "选择照片", 
                    cancel: "取消", 
                    buttons: a 
                }, function(b) { /*actionSheet 按钮点击事件*/ 
                    switch (b.index) { 
                        case 0: 
                            break; 
                        case 1: 
                            getImage(); /*拍照*/ 
                            break; 
                        case 2: 
                            galleryImg();/*打开相册*/ 
                            break; 
                        default: 
                            break; 
                    } 
                }) 
            } 
        }, false); 
 

//拍照上传
//拍照 
        function getImage() { 
            var c = plus.camera.getCamera(); 
            c.captureImage(function(e) { 
                plus.io.resolveLocalFileSystemURL(e, function(entry) { 
                    var s = entry.toLocalURL() + "?version=" + new Date().getTime(); 
                    uploadHead(s); /*上传图片*/ 
                }, function(e) { 
                    console.log("读取拍照文件错误：" + e.message); 
                }); 
            }, function(s) { 
                console.log("error" + s); 
            }, { 
                filename: "_doc/head.png" 
            }) 
        } 
 

//从相册选图上传
//本地相册选择 
        function galleryImg() { 
           	// 从相册中选择图片
    plus.gallery.pick( function(e){
    	for(var i in e.files){
	    	var fileSrc = e.files[i]
//	    	setHtml(fileSrc);
	    	console.log(fileSrc);
	    	uploadHead(fileSrc);
    	}
    }, function ( e ) {
    	console.log( "取消选择图片" );
    },{
    	filter: "image",
    	multiple: true,
    	maximum: 3,
    	system: false,
    	onmaxed: function() {
    		plus.nativeUI.alert('最多只能选择3张图片');
    	}
    });


        }
 

//图片上传和压缩
//上传图片 
        function uploadHead(imgPath) { 
            console.log("imgPath = " + imgPath); 
//          mainImage.src = imgPath; 
//          mainImage.style.width = "60px"; 
//          mainImage.style.height = "60px"; 
 
            var image = new Image(); 
            image.src = imgPath; 
            image.onload = function() { 
                var imgData = getBase64Image(image); 
                /*在这里调用上传接口*/ 
                
                
                hui.loading("图片上传中...");

					var username = localStorage.getItem("username");
					var sec = localStorage.getItem("sec_pwd");
					var time = apiManage.getNow();
					var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
					var paramKey = hex_md5(key);
					var jsonParam = JSON.stringify({
						loginName: username,
						time: time,
						key: paramKey
					});

					var path = urlManager.uploadFile();
					console.log("path-------" + path);

						var form = new FormData();
						//console.log("base64----"+base64String);
						form.append("imgCode", imgData);
						$.ajax({
							type: "POST",
							url: path,
							data: form,
							contentType: false, // 注意这里应设为false
							processData: false, //false
							beforeSend: function(request) {
								request.setRequestHeader("loginName", username);
								request.setRequestHeader("time", time);
								request.setRequestHeader("sign", paramKey);
							},
							success: function(data) {
								console.log("return data-------------" + JSON.stringify(data));
								var imgList = data.pathlist;
								hui.closeLoading();
								settingImgs(imgList);
							}
						});

            } 
    } 
        //将图片压缩转成base64 
        function getBase64Image(img) { 
            var canvas = document.createElement("canvas"); 
            var width = img.width; 
            var height = img.height; 
            
            var settingWH = 500;//限制宽高 
            // calculate the width and height, constraining the proportions 
            if (width > height) { 
                if (width > settingWH) { 
                    height = Math.round(height *= settingWH / width); 
                    width = settingWH; 
                } 
            } else { 
                if (height > settingWH) { 
                    width = Math.round(width *= settingWH / height); 
                    height = settingWH; 
                } 
            } 
            canvas.width = width;   /*设置新的图片的宽度*/ 
            canvas.height = height; /*设置新的图片的长度*/ 
            var ctx = canvas.getContext("2d"); 
            ctx.drawImage(img, 0, 0, width, height); /*绘图*/ 
            var dataURL = canvas.toDataURL("image/png", 0.8); 
            return dataURL.replace("data:image/png;base64,", ""); 
        }    
		
		
		
		
		
		
				

				$("#picture").change(function() {
					var file = this;
					var files = file.files;

					if(files != null && files.length > 0) {
						if(files.length > 3) {
							swal("", "最多只能上传3张照片，请重新选择", "warning");
							return;
						}
						for(var i = 0; i < files.length; i++) {
							uploadFile(files[i]);

						}
					}

				});

				//上传图片
				function uploadFile(file) {

					var username = localStorage.getItem("username");
					var sec = localStorage.getItem("sec_pwd");
					var time = apiManage.getNow();
					var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
					var paramKey = hex_md5(key);
					var jsonParam = JSON.stringify({
						loginName: username,
						time: time,
						key: paramKey
					});

					var path = urlManager.uploadFile();
					console.log("path-------" + path);

					//压缩图片
					lrz(file, {
						width: 300 //设置压缩参数
					}).then(function(rst) {
						/* 处理成功后执行 */

						var base64String = rst.base64
						base64String = base64String.replace("data:image/jpeg;base64,", "");
						var form = new FormData();
						form.append("imgCode", base64String);
						
						hui.loading("");
						$.ajax({
							type: "POST",
							url: path,
							data: form,
							contentType: false, // 注意这里应设为false
							processData: false, //false
							beforeSend: function(request) {
								request.setRequestHeader("loginName", username);
								request.setRequestHeader("time", time);
								request.setRequestHeader("sign", paramKey);
								//													request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
								
							},
							success: function(data) {
								hui.closeLoading();
								console.log("return data-------------" + JSON.stringify(data));
								//														var result = JSON.stringidata);
								var imgList = data.pathlist;

								settingImgs(imgList);
							}
						});

					}).catch(function(err) {
						/* 处理失败后执行 */
					}).always(function() {
						/* 必然执行 */
					})

				}

				settingDateControl("installTime");
				settingDateControl("constructionTime");



				function settingDateControl(pid) {

					var selectDateDom = $('#' + pid);
					var showDateDom = $('#showDate');
					// 初始化时间
					var now = new Date();
					var nowYear = now.getFullYear();
					var nowMonth = now.getMonth() + 1;
					var nowDate = now.getDate();
					selectDateDom.attr('data-year', nowYear);
					selectDateDom.attr('data-month', nowMonth);
					selectDateDom.attr('data-date', nowDate);
					// 数据初始化
					function formatYear(nowYear) {
						var arr = [];
						for(var i = nowYear - 5; i <= nowYear + 5; i++) {
							arr.push({
								id: i + '',
								value: i + '年'
							});
						}
						return arr;
					}

					function formatMonth() {
						var arr = [];
						for(var i = 1; i <= 12; i++) {

							arr.push({
								id: i + '',
								value: i + '月'
							});
						}
						return arr;
					}

					function formatDate(count) {
						var arr = [];
						for(var i = 1; i <= count; i++) {

							arr.push({
								id: i + '',
								value: i + '日'
							});
						}
						return arr;
					}
					var yearData = function(callback) {
						callback(formatYear(nowYear))
					}
					var monthData = function(year, callback) {
						callback(formatMonth());
					};
					var dateData = function(year, month, callback) {
						if(/^(1|3|5|7|8|10|12)$/.test(month)) {
							callback(formatDate(31));
						} else if(/^(4|6|9|11)$/.test(month)) {
							callback(formatDate(30));
						} else if(/^2$/.test(month)) {
							if(year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
								callback(formatDate(29));
							} else {
								callback(formatDate(28));
							}
						} else {
							throw new Error('month is illegal');
						}
					};
					var hourData = function(one, two, three, callback) {
						var hours = [];
						for(var i = 0, len = 24; i < len; i++) {
							if(i < 10) {
								i = "0" + i;
							}
//							hours.push({
//								id: i,
//								value: i + '时'
//							});
						}
						callback(hours);
					};
					var minuteData = function(one, two, three, four, callback) {
						var minutes = [];
						for(var i = 0, len = 60; i < len; i++) {
							if(i < 10) {
								i = "0" + i;
							}
//							minutes.push({
//								id: i,
//								value: i + '分'
//							});
						}
						callback(minutes);
					};
					selectDateDom.bind('click', function() {
						var oneLevelId = selectDateDom.attr('data-year');
						var twoLevelId = selectDateDom.attr('data-month');
						var threeLevelId = selectDateDom.attr('data-date');
						var fourLevelId = selectDateDom.attr('data-hour');
						var fiveLevelId = selectDateDom.attr('data-minute');
						var iosSelect = new IosSelect(3, [yearData, monthData, dateData], {
							title: '选择时间',
							itemHeight: 35,
							itemShowCount: 9,
							oneLevelId: oneLevelId,
							twoLevelId: twoLevelId,
							threeLevelId: threeLevelId,
//							fourLevelId: fourLevelId,
//							fiveLevelId: fiveLevelId,
							callback: function(selectOneObj, selectTwoObj, selectThreeObj) {
								selectDateDom.attr('data-year', selectOneObj.id);
								selectDateDom.attr('data-month', selectTwoObj.id);
								selectDateDom.attr('data-date', selectThreeObj.id);
//								selectDateDom.attr('data-hour', selectFourObj.id);
//								selectDateDom.attr('data-minute', selectFiveObj.id);
								//                  showDateDom.html(selectOneObj.value + ' ' + selectTwoObj.value + ' ' + selectThreeObj.value + ' ' + selectFourObj.value + ' ' + selectFiveObj.value);
								var params = selectOneObj.value + '' + selectTwoObj.value + '' + selectThreeObj.value + '';
								console.log(params);
								params = params.replace("年", "-");
								params = params.replace("月", "-");
								params = params.replace("日", " ");
//								params = params.replace("时", ":");
//								params = params.replace("分", "");

								sp.params[pid] = params;
								$("#" + pid).val(params);
							}
						});
					});

				}

			});
		</script>

	</body>

</html>